package com.housekeeping.housekeeping.administrator.adminsinformation.controller;

import com.alibaba.fastjson.JSONObject;
import com.housekeeping.housekeeping.administrator.adminsinformation.service.update.NewService;
import com.housekeeping.housekeeping.administrator.adminsinformation.service.update.NewServiceImpl;
import com.housekeeping.housekeeping.administrator.entity.AdminsInformation;
import com.housekeeping.housekeeping.administrator.utils.ResponseEntity;
import com.housekeeping.housekeeping.administrator.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/information/new")
public class NewController extends HttpServlet {
    private NewService newService=new NewServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html:charset=utf-8");
        String admins = req.getParameter("data");
        AdminsInformation adminsInformation = JSONObject.parseObject(admins, AdminsInformation.class);
        String jurisdiction = newService.newAfter(adminsInformation);
        ResponseEntity<String> entity=null;
        try {
            if (jurisdiction!=null){
                entity = ResponseEntity.success(jurisdiction);
            }
        }catch (Exception ex){
            entity=ResponseEntity.error(404,"系统繁忙");
        }
        ResponseUtils.responseJson(resp,entity);
    }
}
